package com.mall4j.cloud.user.infrastructure.persist.repository;

import com.alibaba.fastjson2.JSON;
import com.mall4j.cloud.user.domain.entity.User;
import com.mall4j.cloud.user.domain.repository.UserRepository;
import com.mall4j.cloud.user.infrastructure.persist.dao.UserMapper;
import com.mall4j.cloud.user.infrastructure.persist.po.UserPo;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class UserRepositoryImpl implements UserRepository {

    @Resource
    UserMapper userMapper;

    @Override
    public void save(User user) {
        UserPo userPo = new UserPo();
        userPo.setNickName(user.getNickName());
        userPo.setStatus(user.getStatus());
        userPo.setCreateTime(user.getCreateTime());
        userPo.setUpdateTime(user.getUpdateTime());
        log.info("持久化用户成功 {}", JSON.toJSONString(user));
        userMapper.insert(userPo);
    }
}
